home *** CD-ROM | disk | FTP | other *** search
- %%%
- %%% the read_in predicates
- %%%
-
- %%% tested using Arity Prolog V3.2
-
- %%% Donated by:
- %%%
- %%% Whitfield Gregg
- %%% Nourse, Gregg & Browne, Inc.
- %%% 61 Jane St.
- %%% New York, NY 10014
-
- %%% Help from: Deyi Li
-
- %%%
- %%% The read_in goal will take input from the use's terminal
- %%% and return the input line as a list of atoms.
- %%%
- %%% for example:
- %%%
- %%% read_in(Z).
- %%% this is a test
- %%% Z = [this,is,a,test]
- %%%
-
- read_in([W|Ws]) :-
- get0(C),
- readword(C,W,C1),
- w \== [],
- restsent(C1,Ws),
- !.
-
- read_in([]) :- !. % An empty line
-
- restsent(13,[]) :- !. % the rest of the sentence was empty
-
- restsent(C,[W1|Ws]) :-
- readword(C,W1,C1),
- W1 \== [],
- restsent(C1,Ws).
-
- restsent(_,[]) :- !.
-
- readword(C,W,C2) :-
- in_word(C,NewC),
- !,
- get0(C1),
- restword(C1,Cs,C2),
- name(W,[NewC|Cs]).
-
- readword(13,[],_) :- !. % the first is a 'return'
-
- readword(_,W,C2) :-
- get0(C1),
- readword(C1,W,C2).
-
- restword(C,[NewC|Cs],C2) :-
- in_word(C,NewC),
- !,
- get0(C1),
- restword(C1,Cs,C2).
-
- restword(C,[],C).
-
- %%% table of valid characters within a word.
-
- in_word(C,C) :- C > 96, C < 123.
- in_word(C,C) :- C > 64, C < 91.
- in_word(C,C) :- C > 46, C < 58.
- in_word(C,C) :- C > 38, C < 44.
- in_word(C,C) :- C > 59, C < 63.
-